package com.wenli.graduate2022.wenliGreenShop.repository.mapper;

import com.wenli.graduate2022.wenliGreenShop.entity.Review;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author HuangHai
 * @date 2021/10/13 15:51
 */
@Repository
public interface ReviewMapper {

    @Results(id = "review",value= {
            @Result(property = "reviewUser", column = "review_user_id",
                    one = @One(select = "com.wenli.graduate2022.wenliGreenShop.repository.mapper.UserMapper.findById",
                            fetchType = FetchType.LAZY)),
            @Result(property = "reviewProduct", column = "review_product_id",
                    one = @One(select = "com.wenli.graduate2022.wenliGreenShop.repository.mapper.ProductMapper.findById",
                            fetchType = FetchType.LAZY)),
            @Result(property = "reviewOrderItem", column = "review_orderItem_id",
                    one = @One(select = "com.wenli.graduate2022.wenliGreenShop.repository.mapper.ProductOrderItemMapper.findById",
                            fetchType = FetchType.LAZY))
    })
    @Select("select * from where review_user_id = #{id}")
    List<Review> findByUserId(Integer id);   //查询该用户所发出的所有评论

    @Select("select * from where review_product_id = #{id}")
    @ResultMap("review")
    List<Review> findByProductId(Integer id);  //查询该产品下的所有留言
}
